package com.guofen.controller.shlj;

import com.guofen.pojo.ShljDeodorizationtowerWaterChange1;
import com.guofen.pojo.ShljStorageBoxClean;
import com.guofen.service.shlj.StorageBoxCleanService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RequestMapping("/shlj/storageBoxClean")
@Controller
@Api(tags = "StorageBoxCleanController", description = "可燃物储料箱、可腐物储料箱清运记录表")
public class StorageBoxCleanController {

    @Autowired
    private StorageBoxCleanService service;

    //保存
    @ApiOperation("添加记录")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Result add(@ApiParam(name="wagonNumber",value="车号",required=true) @RequestParam String wagonNumber,
                      @ApiParam(name="arrivalTime",value="来厂时间",required=true) @RequestParam String arrivalTime,
                      @ApiParam(name="leaveTime",value="离厂时间",required=true) @RequestParam String leaveTime,
                      @ApiParam(name="cleanWeightstr",value="清运物料重量",required=true) @RequestParam String cleanWeightstr,
                      @ApiParam(name="residueWeightstr",value="剩余物料重量",required=true) @RequestParam String residueWeightstr,
                      @ApiParam(name="cleanType",value="清运物料类型",required=true) @RequestParam String cleanType,
                      @ApiParam(name="residueType",value="剩余物料类型",required=true) @RequestParam String residueType,
                      @ApiParam(name="recordingPerson",value="记录人",required=true) @RequestParam String recordingPerson,
                      @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks){
        Double cleanWeight = Double.parseDouble(cleanWeightstr);
        Double residueWeight = Double.parseDouble(residueWeightstr);
        if (service.add(wagonNumber,arrivalTime,leaveTime,cleanWeight,residueWeight,cleanType,residueType,recordingPerson,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(service.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="wagonNumber",value="车号",required=true) @RequestParam String wagonNumber,
                         @ApiParam(name="arrivalTime",value="来厂时间",required=true) @RequestParam String arrivalTime,
                         @ApiParam(name="leaveTime",value="离厂时间",required=true) @RequestParam String leaveTime,
                         @ApiParam(name="cleanWeight",value="清运物料重量",required=true) @RequestParam Double cleanWeight,
                         @ApiParam(name="residueWeight",value="剩余物料重量",required=true) @RequestParam Double residueWeight,
                         @ApiParam(name="cleanType",value="清运物料类型",required=true) @RequestParam String cleanType,
                         @ApiParam(name="residueType",value="剩余物料类型",required=true) @RequestParam String residueType,
                         @ApiParam(name="recordingPerson",value="记录人",required=true) @RequestParam String recordingPerson,
                         @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks) {
        ShljStorageBoxClean record = new ShljStorageBoxClean();
        record.setId(id);
        record.setWagonNumber(wagonNumber);
        record.setArrivalTime(arrivalTime);
        record.setLeaveTime(leaveTime);
        record.setCleanWeight(cleanWeight);
        record.setResidueWeight(residueWeight);
        record.setCleanType(cleanType);
        record.setResidueType(residueType);
        record.setRecordingPerson(recordingPerson);
        record.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(service.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(service.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(service.getByTime(pageSize, currentPage, startTime, endTime));
    }

    @ApiOperation("获取 当日 最新 一条记录")
    @RequestMapping(value = "/getlast",method = RequestMethod.GET)
    @ResponseBody
    public Result get(){
        return  ResultGenerator.genSuccessResult(service.getlast());
    }
}
